
#include <iostream>
#include <robot/IOPort.hpp>
#include <pthread.h>

#include <luabind/lua_include.hpp>
#include <luabind/luabind.hpp>

typedef robot::IOPort< int > IOPortInt;

class MyInt
{
	public:
		MyInt() : m_test( -5 )
		{
			NotifyChange( MyInt, onNewInt, m_int);
			m_int << -1;
		}

		IOPortInt m_int;
		int m_test;

		DeclareNotifier( MyInt, onNewInt, int );

		void onNewInt( int inputPort )
		{
			std::cout << "My Int is : " << inputPort << std::endl;
			m_test = inputPort;
		}
};

class YourInt
{
	public:
		YourInt() : m_test( -13 )
		{
			NotifyChange( YourInt, onNewInt, m_int );
			m_int << 0;
		}

		IOPortInt m_int;
		int m_test;

		DeclareNotifier( YourInt, onNewInt, int );
		void onNewInt( int inputPort )
		{
			std::cout << "Your Int is : " << inputPort << std::endl;
			m_test = inputPort;
		}
};

extern "C" int init(lua_State* L)
{
    using namespace luabind;

    open(L);

    module(L)
    [
      class_< IOPortInt >("IOPort")
      .def(constructor<>())
      .def("push",&IOPortInt::push)
      .def("sync",&IOPortInt::sync)
      .def("<<",&IOPortInt::operator<<)
      .def("=",&IOPortInt::operator=),
      class_<MyInt>("MyInt")
      .def(constructor<>())
      .def_readwrite("m_test",&MyInt::m_test)
      .def_readonly("m_int",&MyInt::m_int)
    ];

    return 0;
}
